package com.xja.zf.controller;

import com.xja.zf.entity.House;
import com.xja.zf.service.ManageService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("manage")
public class ManageController {
    private Logger logger= LoggerFactory.getLogger(ManageController.class);
    @Reference(url="dubbo://localhost:20882")
    private ManageService manageService;

    @RequestMapping("init")
    public String init(Model model){
        logger.info("这是初始化list界面的方法");
        try {
            List<House> houseList=manageService.selectHouse(null);
            Map<String, Object> map=manageService.init();
            model.addAttribute("streetList",map.get("streetList"));
            model.addAttribute("htypeList",map.get("htypeList"));
            model.addAttribute("houseList",houseList);
            return "list";
        }catch (Exception ex){
            logger.error("初始化失败",ex);
        }
        return "login";
    }

    @RequestMapping("todetails")
    public String todetails(Model model,Integer id){
        logger.info("这是房屋详情方法");
        try {
            House house=manageService.selectById(id);
            model.addAttribute("house",house);
            return "details";
        }catch (Exception ex){
            logger.error("房屋详情方法失败",ex);
        }
        return "redirect:/init";
    }


}
